class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution(object):
    def sufficientSubset(self, root, limit):
        def dfs(node, now):
            now += node.val
            if not node.left and not node.right:
                if now < limit:
                    return None
                else:
                    return node
            if node.left:
                node.left = dfs(node.left, now)
            if node.right:
                node.right = dfs(node.right, now)
            if not node.left and not node.right:
                return None
            else:
                return node
        return dfs(root, 0)
